package com.hgy.carsb.entity;

import lombok.Data;

import java.math.BigDecimal;

@Data
public class StructureDetail {
    private String thisYearSum;
    private String lastYearSum;
    private String monthRate;
    private String yearRate;

    public StructureDetail(){}

    public StructureDetail(String thisMonth, String lastMonth, String thisYearSum, String lastYearSum){
        this.thisYearSum = thisYearSum;
        this.lastYearSum = lastYearSum;
        BigDecimal subYear = new BigDecimal(thisYearSum).subtract(new BigDecimal(lastYearSum));
        BigDecimal subMonth = new BigDecimal(thisMonth).subtract(new BigDecimal(lastMonth));
        if (lastMonth.equals("0")){
            monthRate = "0";
        }else {
            BigDecimal rate = subMonth.multiply(new BigDecimal(100)).divide(new BigDecimal(lastMonth), 2, BigDecimal.ROUND_HALF_UP);
            rate = rate.setScale(2, BigDecimal.ROUND_HALF_UP);
            monthRate = rate.toString();
        }
        if (lastYearSum.equals("0")){
            yearRate = "0";
        }else {
            BigDecimal rate = subYear.multiply(new BigDecimal(100)).divide(new BigDecimal(lastYearSum), 2, BigDecimal.ROUND_HALF_UP);
            rate = rate.setScale(2, BigDecimal.ROUND_HALF_UP);
            yearRate = rate.toString();
        }
    }
}
